package cn.wolfcode.trip.base.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间工具类
 */
public abstract class DateUtil {

    /**
     * 获取传入时间的最后一秒
     *
     * @return
     */
    public static Date getEndDate(Date date) {
        if (date == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);  //时
        calendar.set(Calendar.MINUTE, 59);//分
        calendar.set(Calendar.SECOND, 59);//秒
        return calendar.getTime();
    }


    public static String date2string(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}
